package linux;


import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;


import jodd.io.NetUtil;

public class Linux {

	public static void main(String[] args) {
		String maintainerFileUrl = "https://github.com/torvalds/linux/raw/refs/heads/master/MAINTAINERS";
		int startLineNo = 68;
		String[] maintainerFileLines = null;
		try {
			maintainerFileLines = NetUtil.downloadString(maintainerFileUrl, StandardCharsets.UTF_8).split("\n");
		} catch (IOException e) {
			e.printStackTrace();
		}
		List<String> maintainedModules = new ArrayList<>();
		List<String> orphanModules = new ArrayList<>();
		for(int i=startLineNo;maintainerFileLines!=null && i<maintainerFileLines.length;i++) {
			String line = maintainerFileLines[i];
			if(line.strip().isBlank()) {
				String moduleName = maintainerFileLines[i+1];
				String moduleMaintainer = maintainerFileLines[i+2];
				if(moduleMaintainer.startsWith("M:")) {
					
					maintainedModules.add(moduleName+":\t"+moduleMaintainer.substring(2));
				}else {
					orphanModules.add(moduleName+":\tnull");
				}
			}
		}
		System.out.println("=================");
		System.out.println("***Maintained***: ");
		System.out.println(String.join("\n", maintainedModules));
		System.out.println("***Maintained***: "+maintainedModules.size());
		
		System.out.println("=================");
		System.out.println("***Orphan***: ");
		System.out.println(String.join("\n", orphanModules));
		System.out.println("***Orphan***: "+orphanModules.size());
	}

}
